<?php 
class DomArCustomTestsTestCase extends DomArTestUnitTestCase {
	
	
	public function test1() {
	
		CustomTestParent::getTable()->update();
	
		$a = new CustomTestParent();
		$b = new CustomTestChild();
		
		$a->children[] = $b;
		$b->children[] = $a;
		
		$a->save();
		
		DomAr::flushStoredObjects();
		$aa = CustomTestParent::load( $a->id );
		$bb = $aa->parent;
		$children = $aa->children->query()->commit()->toArray();
		$this->assertEqual( $children[0], $bb );
		$this->assertEqual( count($children), 1);
		
		$children = $bb->children->query()->commit()->toArray();
		$this->assertEqual( $children[0], $aa );
		$this->assertEqual( count($children), 1);
		
		$aa->delete();
		$bb->delete();
		
	}
	
	
	public function testComplex1() {
		
		C1_Thread::getTable()->update();
		
		
		$thread = new C1_Thread();
		$user = new C1_User();
		$topic = new C1_Topic();
		
		$thread->topics[] = $topic;
		$topic->user = $user;
		$topic->thread = $thread;
		$thread->user = $user;
		
		$thread->save();
		
		$this->assertEqual( C1_Thread::dataQuery()->select('count(*) as n')->limit(1)->commit(), array('n'=>1) );
		$this->assertEqual( C1_User::dataQuery()->select('count(*) as n')->limit(1)->commit(), array('n'=>1) );
		$this->assertEqual( C1_Topic::dataQuery()->select('count(*) as n')->limit(1)->commit(), array('n'=>1) );
	
		//debug( DomArEventTree::trace() );
	
	}
	
} 
?>